#!/bin/bash

pair=$1
if [ -z "$1" ]; then
    pair="BTC"
else
    pair="$1"
fi
pair=$(echo "$pair" | tr '[:lower:]' '[:upper:]')
url="https://api.binance.com/api/v3/ticker/price?symbol={$pair}USDT"
response=$(curl -s "$url")
if [ $? -eq 0 ]; then
  price=$(grep -o '"price":"[^"]*' <<< "$response" | grep -o '[^"]*$')
  if [ -n "$price" ]; then
    echo $price
  else
    msg=$(grep -o '"msg": "[^"]*' <<< "$response" | grep -o '[^"]*$')
    if [ -n "$msg" ]; then
      echo $msg
    else
      echo "无法解析price字段。"
    fi
  fi
else
  echo "无法获取接口数据，请检查接口和网络连接。"
fi